package com.skateboard.reelviewtest

import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.view.animation.AnimationUtils
import androidx.appcompat.app.AppCompatActivity
import com.skateboard.reelviewtest.R.layout
import com.skateboard.reelviewtest.utils.SimpleUtils
import com.skateboard.reelviewtest.view.reelview.UxinReelView
import com.skateboard.reelviewtest.view.reelview.UxinReelView.ReelExpandCallBack
import kotlinx.android.synthetic.main.activity_main.*


class ReelActivity: AppCompatActivity()
{
    val str = "最开始的时候,你并不熟悉这座陌生的城市,你甚至摸得到内心那种无法融入的恐慌和彷徨,据说,这种感觉叫漂泊。皮卡丘！！！"
    var value=0
    val handle= object :Handler(){
        override fun handleMessage(msg: Message?) {
            super.handleMessage(msg)
            if (tv.text.length - 1 < value&&!TextUtils.isEmpty(str)&&str.length>value) {

                val txt = str.substring(0, value + 1)
                tv.text = txt
                Log.e("ssss", "$txt===============")
                value++
            }
            if(value<str.length){
                test()
            }
        }
    }

    private fun test(){
        handle?.sendEmptyMessageDelayed(0,100)
    }

    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        setContentView(layout.activity_main)
        reel_view.reelExpandCallBack=object : ReelExpandCallBack {
            override fun callBackExpandEnd(isExpand: Boolean) {
                if(isExpand){
                    scrollview.visibility= View.VISIBLE
                    iv_title.visibility = View.VISIBLE
                    iv_title.animation = AnimationUtils.makeInAnimation(this@ReelActivity, false)
                    tv.text=""
                    value=0
                    handle?.sendEmptyMessageDelayed(0,200)

                }else{
                    scrollview.visibility= View.GONE
                    iv_title.visibility = View.GONE
                }
                Log.e("ssss", "======ReelExpandCallBack=========$isExpand")
            }

            override fun callBackExpandStart(isExpand: Boolean) {
                if(!isExpand){
                    scrollview.visibility= View.GONE
                }
            }

        }

    }





}